<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996  15899929162
// +----------------------------------------------------------------------
namespace app\common\model\work;

use app\common\model\BaseModel;
use app\common\model\users\UsersModel;
use app\common\model\approval\ApprovalReceivesModel;

class WorkExpendApplyModel extends BaseModel
{
    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'add_time';
    protected $updateTime = false;

    public static function tablePk(): string
    {
        return 'id';
    }

    public static function tableName(): string
    {
        return 'work_expend_apply';
    }

    public function userInfo()
    {
        return $this->hasOne(UsersModel::class, 'id', 'user_id');
    }

    public function cateInfo()
    {
        return $this->hasOne(WorkCateModel::class, 'id', 'cate_id');
    }

    public function presentUserInfo()
    {
        return $this->hasOne(UsersModel::class, 'id', 'present_uid');
    }

    /**
     *  审核列表
     * @return \think\model\relation\HasMany
     *
     * @author Amos
     * 2024-05-24 08:00
     */
    public function ReceivesListData()
    {
        return $this->hasMany(ApprovalReceivesModel::class, 'source_id', 'id')
            ->where('flow_type', 'expend_apply')
            ->where('verify_type', 1);
    }

    /**
     *  抄送列表
     * @return \think\model\relation\HasMany
     *
     * @author Amos
     * 2024-05-24 08:00
     */
    public function CopyListData()
    {
        return $this->hasMany(ApprovalReceivesModel::class, 'source_id', 'id')
            ->where('flow_type', 'expend_apply')
            ->where('verify_type', 3);
    }

    public function getPictureAttr($value)
    {
        return array_filter(explode(',', $value));
    }

    public function setPictureAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

}
